import gcoord from "../../../../miniprogram_npm/gcoord/dist/gcoord";
import Toast from "../../../../miniprogram_npm/@vant/weapp/toast/toast";
import Dialog from "../../../../miniprogram_npm/@vant/weapp/dialog/dialog";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    Company: {},
    allData: "",
    vipCode: "",
  },

  vagueClick() {
    wx.showModal({
      title: '提示',
      content: '该功能为VIP会员功能，请联系客服了解详情。',
      showCancel: false,
      confirmText: '确定',
      success: function () {}
    })

  },
  Business(e) {
    wx.navigateTo({
      url: "../CompanyDetails/CompanyDetails?corpKey=" +
        e.currentTarget.dataset.proindex,
    });
  },
  deuce() {
    // wx.navigateTo({
    //   url: '../deuce/deuce'
    // })
  },
  concern(event) {
    var _this = this;
    console.log(_this.data.Company.companyId);
    if (this.data.token !== "") {
      getApp()
        .globalData.request(
          "/api/authorize/user/info", {
            companyId: _this.data.Company.companyId,
          },
          "POST",
          "application/x-www-form-urlencoded"
        )
        .then((res) => {
          console.log(res);
          if (res.code == 200) {
            wx.request({
              url: `https://fintech-wx.szjrgzjg.com/api/userApi/unsubscribeCompany`,
              header: {
                token: _this.data.token,
                "Content-Type": "application/x-www-form-urlencoded",
              },
              data: {
                companyId: event.currentTarget.id,
              },
              method: "post",
              success(data) {
                if (data.statusCode == 200) {
                  _this.setData({
                    "Company.status": 1,
                  });
                }
              },
            });
          } else {
            Dialog.confirm({
                title: "",
                message: "请先登录！",
              })
              .then(() => {
                wx.navigateTo({
                  url: "/pages/login/login",
                });
              })
              .catch(() => {
                // on cancel
                wx.switchTab({
                  url: "/pages/Attorney/Attorney",
                });
              });
          }
        });
    } else {
      Dialog.confirm({
          title: "",
          message: "请先登录！",
        })
        .then(() => {
          wx.navigateTo({
            url: "/pages/login/login",
          });
        })
        .catch(() => {
          // on cancel
          wx.navigateTo({
            url: "/pages/Attorney/Attorney",
          });
        });
    }
  },
  PickUp(event) {
    var _this = this;
    console.log(event.currentTarget.id);
    wx.request({
      url: `https://fintech-wx.szjrgzjg.com/api/userApi/unsubscribeCompany`,
      header: {
        token: _this.data.token,
        "Content-Type": "application/x-www-form-urlencoded",
      },
      data: {
        companyId: event.currentTarget.id,
      },
      method: "post",
      success(data) {
        if (data.statusCode == 200) {
          _this.setData({
            "Company.status": 0,
          });
        } else {
          Dialog.confirm({
              title: "",
              message: "请先登录！",
            })
            .then(() => {
              wx.navigateTo({
                url: "/pages/login/login",
              });
            })
            .catch(() => {
              // on cancel
              wx.navigateTo({
                url: "/pages/Attorney/Attorney",
              });
            });
        }
      },
    });
  },
  phone(event) {
    console.log(event.currentTarget, 'event.currentTarget.id');
    if (event.currentTarget.id !== '暂无电话') {
      wx.makePhoneCall({
        phoneNumber: event.currentTarget.id,
      });
    } else {
      Toast("暂无电话");
    }
  },
  // 中心点坐标转化
  transMarker1(item) {
    const resae = gcoord.transform(
      [item[0], item[1]],
      gcoord.BD09, // 当前坐标系
      gcoord.GCJ02 // 目标坐标系0
    );
    return resae;
  },
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {

    getApp()
      .globalData.request(
        "/map/query/credit_limit/detail", {
          corpKey: options.corpKey,
        },
        "POST"
      )
      .then((rstObj) => {
        if (rstObj.code == 200) {
          rstObj.data.longitude = rstObj.data.longitude ? this.transMarker1([rstObj.data.longitude, rstObj.data.latitude])[0] : '',
            rstObj.data.latitude = rstObj.data.longitude ? this.transMarker1([rstObj.data.latitude, rstObj.data.latitude])[1] : '',
            this.setData({
              Company: rstObj.data,
              allData: {
                score: rstObj.data.score
              },
            });
        }
      });
    const vipCode = await getApp().globalData.checkVipStatus()
    if (vipCode == 'ordinary' || vipCode == 'notVipBindFI' || vipCode == 'visitor') {
      this.setData({
        canLook: 'no'
      })
    }else{
      this.setData({
        canLook: 'yes'
      })
    }
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});